import type { MpKuaiShouInfo, MpTouTiaoInfo, MpWeiXinInfo, MxpReleaseReviewConfig } from './vite/cli/types.ts';
import { ksMpConfig } from './src/config/mp/ks.ts';
import { ttMpConfig } from './src/config/mp/tt.ts';
import { wxMpConfig } from './src/config/mp/wx.ts';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const defaultVersion = '2.1.22';

/** 更新说明 */
const desc = '修复bug';

/** 快手小程序相关配置 */
const kuaishouList: MpKuaiShouInfo[] = Object.values(ksMpConfig).map((item) => {
  const privateKeyPath = resolve(__dirname, `build-utils/upPrivateKey/private.${item.appid}.key`);
  return { name: item.name, appid: item.appid, desc, privateKeyPath, version: defaultVersion };
});

/** 头条小程序相关配置 */
const toutiaoList: MpTouTiaoInfo[] = Object.values(ttMpConfig).map((item) => {
  return { name: item.name, appid: item.appid, token: item.token, desc, version: defaultVersion };
});

/** 微信小程序相关配置 */
const weixinList: MpWeiXinInfo[] = Object.values(wxMpConfig).map((item) => {
  const privateKeyPath = resolve(__dirname, `build-utils/upPrivateKey/private.${item.appid}.key`);
  return { name: item.name, appid: item.appid, desc, privateKeyPath, version: defaultVersion };
});

/** 配置 */
const config: MxpReleaseReviewConfig = {
  /** 快手小程序相关配置 */
  'mp-kuaishou': {
    appList: kuaishouList,
  },
  /** 头条小程序相关配置 */
  'mp-toutiao': {
    /** 是否提交审核 */
    audit: true,
    /** 需要提交的小程序 */
    appList: toutiaoList,
  },
  /** 微信小程序相关配置 */
  'mp-weixin': { appList: weixinList },
};

export default config;
